package com.eat.controller.admin;

import com.eat.dto.OrdersCancelDTO;
import com.eat.dto.OrdersConfirmDTO;
import com.eat.dto.OrdersPageQueryDTO;
import com.eat.dto.OrdersRejectionDTO;
import com.eat.entity.Orders;
import com.eat.result.PageResult;
import com.eat.result.Result;
import com.eat.service.OrderService;
import com.eat.vo.OrderStatisticsVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "订单管理接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 分页查询订单
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("conditionSearch")
    public Result<PageResult> getPage(OrdersPageQueryDTO ordersPageQueryDTO){

        PageResult pageResult =  orderService.getPage(ordersPageQueryDTO);

        return Result.success(pageResult);
    }

    /**
     * 查询订单详细信息
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public Result<Orders> getOrderById(@PathVariable Long id){

        Orders orders = orderService.getOrder(id);

        return Result.success(orders);
    }

    /**
     * 接单
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){

        orderService.confirm(ordersConfirmDTO);

        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){

        orderService.delivery(id);

        return Result.success();

    }

    /**
     * 拒单
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){

        orderService.rejection(ordersRejectionDTO);

        return Result.success();
    }

    /**
     * 完成订单
     * @return
     */
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){


        orderService.complete(id);

        return Result.success();
    }

    /**
     * 取消订单
     * @return
     */
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){

        orderService.cancel(ordersCancelDTO);

        return Result.success();
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){

            OrderStatisticsVO statisticsVO = orderService.statistics();

        return Result.success(statisticsVO);
    }

}
